﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data.Car_Rental;
using Entity.Car_Rental;
namespace Service.Rental
{
    /// <summary>
    /// 商品模块实现
    /// </summary>
    public class ProductService : ServiceBase, IProductService
    {
        IProductRepository iProductRepository = null;
        /// <summary>
        /// 默认构造方法
        /// </summary>
        public ProductService()
            : this(new ProductRepository())
        {

        }
        /// <summary>
        /// 构造方法，可以在建立实例时进行实现方式的选择
        /// </summary>
        /// <param name="_iProductRepository"></param>
        public ProductService(IProductRepository _iProductRepository)
        {
            iProductRepository = _iProductRepository;
        }
        #region IProductService 成员

        public Entity.VMessage AddProduct(Entity.Car_Rental.Product entity)
        {
            try
            {
                iProductRepository.Insert(entity);
                VMessage.IsComplete = true;
            }
            catch (Exception)
            {
                // throw;  //发布后注释它
                VMessage.IsComplete = false;
            }
            return VMessage;
        }

        public Entity.PagedList<Entity.Car_Rental.Product> GetProduct(Entity.VPredication vp, Entity.PagingParam pp)
        {
            var linq = iProductRepository.GetDetailModel();
            return new Entity.PagedList<Entity.Car_Rental.Product>(linq, pp.PageIndex, pp.PageSize);
        }

        #endregion

        #region IGetService<Product> 成员

        public Entity.PagedList<Entity.Car_Rental.Product> GetPagedListModel(Entity.VPredication vp, Entity.PagingParam pp)
        {
            throw new NotImplementedException();
        }

        public Entity.Car_Rental.Product GetSingleModel(object[] primaryKey)
        {
            throw new NotImplementedException();
        }

        #endregion


        public List<Category> GetCategory()
        {
            return LoadRepository<Category>().GetModel().ToList();
        }

        public void InsertCategory(Category entity)
        {
            LoadRepository<Category>().Insert(entity);
        }

        public void DeleteCategory(Category entity)
        {
            LoadRepository<Category>().Delete(entity);
        }
    }
}
